//
//  GTCellTopView.swift
//  swiftWEIbo
//
//  Created by mac－gt on 15/11/27.
//  Copyright © 2015年 mac－gt. All rights reserved.
//

import UIKit

import SDWebImage
class GTCellTopView: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
//        backgroundColor=UIColor.blueColor()
        setUp()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private lazy var iconView: UIImageView={
        let imgView=UIImageView(image: UIImage(named: "avatar"))
        return imgView
    }()
    // 头部分割线的View
    private lazy var topSeparatorView:UIView={
        let view1=UIView()
        view1.backgroundColor=UIColor(white: 0.9, alpha: 1)
      return view1
    }()
    //监听status属性，处理
    var status: GTStatus?{
        didSet{
            if let urlString=status?.user?.profile_image_url{
                let url=NSURL(string: urlString)
                iconView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "common_icon_membership_expired"))
            }
            nameLable.text=status?.user?.screen_name
            timeLable.text=status?.created_at
            sourceLable.text=status?.source
            memberView.image=status?.user?.mbrankImage
            verifiedView.image=status?.user?.verifiedTypeImage

        }
    }
    // 懒加载所有子控件
    private lazy var nameLable=UILabel(textColor: UIColor.darkGrayColor() , fontSize: 14)
    private lazy var timeLable=UILabel(textColor: UIColor.orangeColor(), fontSize: 9)
    private lazy var sourceLable=UILabel(textColor: UIColor.lightGrayColor(), fontSize: 9)
    private lazy var verifiedView=UIImageView()
    private lazy var memberView: UIImageView=UIImageView()
    //添加子控件和约束
    func setUp(){
        addSubview(iconView)
        addSubview(nameLable)
        addSubview(timeLable)
        addSubview(sourceLable)
        addSubview(verifiedView)
        addSubview(memberView)
        addSubview(topSeparatorView)
//        iconView.ff_AlignInner(type: ff_AlignType, referView: topSeparatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topSeparatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        nameLable.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        timeLable.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        sourceLable.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLable, size: nil, offset: CGPoint(x: 8, y: 0))

        memberView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLable, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))

        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
        topSeparatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
    }
}
